<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
            text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router @select="handleSelect">
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
                                    {{ threeItem.title }}
                                </el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.index">
                                {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>
<script>
    import bus from '../bus'
    export default {
        name: 'sidebar',
        data() {
            return {
                collapse: false,
                items: [
                    {
                        icon: 'el-icon-s-home',
                        index: '/home',
                        title: '首页',
                    },
                    {
                        icon: 'el-icon-user-solid',
                        index: 'router1',
                        title: '人员管理',
                        subs:[

                            {
                                index: '/ClassManage',
                                title: '班级管理'
                            },
                            {
                                index: '2',
                                title: '学生管理',
                                subs:[
                                    {
                                        index: '/StudentInfo',
                                        title: '学生信息'
                                    },
                                    {
                                        index: '/BulkImport',
                                        title: '批量导入'
                                    },
                                    {
                                        index: '/BulkSwitch',
                                        title: '批量调班'
                                    },
                                    {
                                        index: '/GraduateSelect',
                                        title: '毕业查询'
                                    },
                                    // {
                                    //     index: '/CardManage',
                                    //     title: '卡号管理'
                                    // },
                                    {
                                        index: '/StudentReport',
                                        title: '学生报表'
                                    }
                                ] 
                            },
                            {
                                index: '3',
                                title: '教工管理',
                                subs: [
                                    {
                                        index: '/StaffInfo',
                                        title: '教工信息'
                                    }
                                ]
                            },
                            {
                                index: '/WeChatRegister',
                                title: '微信注册查询'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-monitor',
                        index: 'router2',
                        title: '考勤管理',
                        subs: [
                            {
                                index: '/ManualPunch',
                                title: '手工打卡'
                            },
                            {
                                index: '/OnlineLeave',
                                title: '在线请假'
                            },
                            {
                                index: '/KitchenSelect',
                                title: '后厨查询'
                            },
                            {
                                index: '/ScreenLive',
                                title: '大屏直播'
                            },
                            {
                                index: '5',
                                title: '学生考勤',
                                subs: [
                                    {
                                        index: '/Student/SchoolStatistical',
                                        title: '在校统计'
                                    },
                                    {
                                        index: '/Student/AttenDanceDetail',
                                        title: '考勤明细'
                                    },
                                    {
                                        index: '/Student/AttenDanceStatistical',
                                        title: '考情统计'
                                    }
                                ]
                            },
                            {
                                index: '6',
                                title: '教工考勤',
                                subs: [
                                    {
                                        index: '/Staff/AttenDanceSetting',
                                        title: '考勤设置',
                                    },
                                    {
                                        index: '/Staff/SchoolStatistics',
                                        title: '在校统计',
                                    },
                                    {
                                        index: '/Staff/AttenDanceDetail',
                                        title: '考勤明细'
                                    },
                                    {
                                        index: '/Staff/AttenDanceStatistical',
                                        title: '考勤统计'
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-suitcase',
                        index: 'router3',
                        title: '设备管理',
                        subs: [
                            {
                                index: '/Equip/DoorMachine',
                                title: '门口机'
                            },
                            {
                                index: '2',
                                title: '班级机'
                            },
                            {
                                index: '3',
                                title: '蓝牙手持机'
                            },
                            {
                                index: '4',
                                title: '直播摄像头'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-news',
                        index: '/Notice',
                        title: '通知'
                    },
                    {
                        icon: 'el-icon-chat-round',
                        index: '/WeChatRegister',
                        title: '微信公众号'
                    },
                    {
                        icon: 'el-icon-bank-card',
                        index: 'router6',
                        title: '校园财务',
                        subs: [
                            {
                                index: '1',
                                title: '资产类型'
                            },
                            {
                                index: '2',
                                title: '费用项目'
                            },
                            {
                                index: '3',
                                title: '收款对象设置'
                            },
                            {
                                index: '4',
                                title: '收款金额设置'
                            },
                            {
                                index: '5',
                                title: '收款登记'
                            },
                            {
                                index: '6',
                                title: '付款登记'
                            },
                            {
                                index: '7',
                                title: '收/付款查询'
                            },
                            {
                                index: '8',
                                title: '催缴推送'
                            },
                            {
                                index: '9',
                                title: '催缴查询'
                            },
                            {
                                index: '10',
                                title: '报表'
                            },
                        ]
                    },
                    {
                        icon: 'el-icon-s-tools',
                        index: 'router7',
                        title: '系统设置',
                        subs: [
                            {
                                index: '/usersSetting',
                                title: '用户设置'
                            },
                            {
                                index: '1',
                                title: '密码设置'
                            },
                            {
                                index: '2',
                                title: '密保手机设置'
                            },
                            {
                                index: '3',
                                title: '修改学校名称'
                            },
                            {
                                index: '4',
                                title: '用户管理'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-document',
                        index: 'router8',
                        title: '使用说明'
                    },
                    {
                        icon: 'el-icon-s-claim',
                        index: '/IcbcOrder',
                        title: '工行订单'
                    },
                    {
                        icon: 'el-icon-tickets',
                        index: '/accessRecords',
                        title: '出入记录'
                    }
                ]
            }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        },
        created() {
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
            bus.$on('toUserSetting', msg => {
                this.$router.push({name: '用户设置'})
                this.handleSelect(`/${msg}`)
            })
        },
        methods: {
            handleSelect(key) {
                console.log(key);
            }
        }
    }
</script>
<style lang="scss">
    .sidebar {
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom: 0;
        overflow-y: scroll;
    }

    .sidebar::-webkit-scrollbar {
        width: 0;
    }

    .sidebar-el-menu:not(.el-menu--collapse) {
        width: 250px;
    }

    .sidebar>ul {
        height: 100%;
    }
</style>